#include "StdAfx.h"
#include "StateStack.h"

StateStack* StateStack::ms_pInstance;

void StateStack::SetState(StateBase* state)
{
	if ( !m_stack.empty() )
	{
		StateBase* lastState = m_stack.top();
		lastState->OnExit();
		
		m_stack.pop();
		m_recycle.push_back(lastState);
	}
	state->OnEnter();
	m_stack.push(state);
}

void StateStack::PushState (StateBase* state)
{
	state->OnEnter();
	m_stack.push(state);
}

void StateStack::PopState()
{
	StateBase* lastState = m_stack.top();
	lastState->OnExit();
	
	m_stack.pop();
	m_recycle.push_back(lastState);
}

StateBase* StateStack::GetCurrentState()
{
	if ( !m_stack.empty() )
	{
		return m_stack.top();
	}
	else
	{
		return NULL;
	}
}